﻿$(function () {
    var _option = {
        data: [
            { id: "bbq", name: "测试一级", type: 0, pid: "0" },
            { id: "bbq1", name: "测试二级", type: 1, url: "/asas.html", pid: "bbq" }
        ],
        dom: $("#nav"),
        pid: "0"
    };
    $("#nav").html("<ul data-pid=\"0\"></ul>");
    Addmaster(_option);
    //注入事件
    $("#nav li[data-type='0']").on('click', function () {
        var that = $(this);
        var imgdom = $(that).children("div:first").children("img:first");
        var uldom = $(that).children("ul");
        console.log(imgdom.attr("src"));
        if (imgdom.hasClass("dxWeb_nbExpand_DevEx")) {
            imgdom.removeClass("dxWeb_nbExpand_DevEx");
            imgdom.addClass("dxWeb_nbCollapse_DevEx");
            uldom.hide();
        }
        else {
            console.log("XX");
            imgdom.removeClass("dxWeb_nbCollapse_DevEx");
            imgdom.addClass("dxWeb_nbExpand_DevEx");
            uldom.show();
        }
    })

    /*
    $("#nav li [data-type='1']").click = function () {
    }*/
    function Addmaster(option) {
        for (var i = 0; i < option.data.length; i++) {
            var item = option.data[i];
            if (item.pid != option.pid) {
                continue;
            }
            else {
                if (item.type == 1) {
                    console.log("xx." + item.pid);
                    var html = "<li data-type=\"1\">"
                    html += "<a href=\"" + item.url + "\"><span class=\"dx-vam\">" + item.name + "</span></a>";
                    html += "</li>";
                    //console.log("ul [data-pid='" + option.pid + "']");
                    console.log(item.pid + "." + option.pid);
                    var xx = $(option.dom).find("ul[data-pid='" + option.pid + "']");
                    console.log(xx);
                    $(option.dom).find("ul[data-pid='" + option.pid + "']").append(html);
                }
                else {
                    //dxWeb_nbCollapse_DevEx dxnb-btn
                    var html = "<li data-type=\"0\">"
                    html += "<div class=\"dxnb-headerCollapsed navGp\">"
                    html += "<img class=\"dxWeb_nbExpand_DevEx dxnb-btn\" src=\"/DXR.axd?r=1_58-qg6Dg\"";
                    html += "style=\"margin-top: 1.5px;\"\\><span class=\"dxnb-ghtext dx-vam\" style=\"margin-right: 17px !important;\">";
                    html += item.name;
                    html += "</span></div>";
                    html += "<ul data-pid='" + item.id + "'></ul></li>";
                    $(option.dom).find("ul[data-pid='" + option.pid + "']").append(html);
                    Addmaster({ data: option.data, pid: item.id, dom: option.dom });
                }
            }
        }
    }
})